package remoto;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import dominio.OrdenCompra;
import dto.OrdenCompraTO;

public class GestionOrdenesCompra {
	private static GestionOrdenesCompra instance;

	public static GestionOrdenesCompra getInstance() throws MalformedURLException, RemoteException, NotBoundException {
		if (instance == null)
			instance = new GestionOrdenesCompra();
		return instance;
	}

	private IGestionOrdenesCompra remoto;

	private GestionOrdenesCompra() throws MalformedURLException, RemoteException, NotBoundException {
		remoto = (IGestionOrdenesCompra) Naming.lookup("GestionOrdenesCompra");
	}

	public int guardarOrdenCompra(OrdenCompra o) throws RemoteException {
		return remoto.guardarOrdenCompra(o.getDTO());
	}
	
	public OrdenCompra buscarOrdenCompra(int id) throws RemoteException {
		OrdenCompraTO dto = remoto.buscarOrdenCompra(id);
		if (dto != null)
			return OrdenCompra.fromDTO(dto);
		return null;
	}
}